package com.xyj.week01;

import java.util.Arrays;

/**
 * 给出一个有序数组  找到两数的和
 */
public class T8 {

    public static void main(String[] args) {

        int[] ints = {2, 3, 5, 5, 6, 7};
        int[] compose = getTheComposeOfTarget(ints, 8);
        System.out.println(Arrays.toString(compose));

    }
    public static int [] getTheComposeOfTarget(int [] nums,int target){
        if (nums.length==0||nums.length==1){
            return new int[]{-1,-1};
        }
        int left =0;
        int right = nums.length-1;
        while (left<right){
            int sum = nums[left]+nums[right];
            if (sum==target){
                return new int[] {left,right};
            }else if (sum<target){
                left ++;
            }else {
                right --;
            }
        }
        return new int[] {-1,-1};
    }
}
